<template>
	<view class="homePage">
		<image class="bgc" src="../../static/bgc.jpg"></image>
		<image src="../../static/form.png" class="form" mode="widthFix"></image>

		<view class="box">
			<text>#</text>
			<input type="text" v-model="password" class="password" placeholder="请输入定单号..." p>
		</view>
		<image src="../../static/kaisuo.png" class="suo" mode="widthFix" @click="go"></image>
		<!-- #ifdef MP-WEIXIN -->
		<!-- #endif -->
	</view>
</template>

<script>
	import {
		apiCheck,
		apiOpendoork
	} from '@/api/common.js'
	export default {
		data() {
			return {
				password: '',
				id: '',
				pwd: '',
				// dev_id: '39292',
				// dev_pwd: 'mar68',
				dev_id: '39430',
				dev_pwd: 'wan69',
				url:'',
				clock: 'close',
			}
		},
		onLoad(option) {
			if (option.id) {
				this.dev_id = option.id
				this.dev_pwd = option.pwd
			}
		},
		methods: {
			go(str) {

				if (this.password.trim() !== '') {
					uni.showLoading({
						mask: true
					})
					if (this.dev_id == '39255') {
						this.url = 'https://chuku.snowmetal.cn'
					} else if (this.dev_id == '39292') {
						this.url = 'https://chuku2.snowmetal.cn'
					} else if (this.dev_id == '39430') {
						this.url = 'https://chuku3.snowmetal.cn'
					}
					apiCheck(this.url+
						'/index/user/check.html', {
							post_code: this.password
						}).then(res => {
						if (res && res instanceof Array && res.length > 0) {
							this.trigger(()=>{
								uni.navigateTo({
									url: '/pages/kaisuo/index?args=' + encodeURIComponent(JSON.stringify({
										dev_id: this.dev_id,
										dev_pwd: this.dev_pwd,
										...res[
											0],
										str: str
									}))
								})
							})
							

						} else {
							uni.showToast({
								title: '该订单已出库（或订单号错误）',
								icon: 'none'
							})
						}
					})
				} else {
					uni.showToast({
						title: '请输入定单号',
						icon: 'none'
					})
				}
			},
			trigger(cb) {
				if (this.clock == 'opening' || this.clock == 'open') return false
				this.loading = true
				this.clock = 'opening'
				if (this.dev_id == '39255') {
					this.url = 'https://chuku.snowmetal.cn'
				} else if (this.dev_id == '39292') {
					this.url = 'https://chuku2.snowmetal.cn'
				} else if (this.dev_id == '39403') {
					this.url = 'https://chuku3.snowmetal.cn'
				}
				apiOpendoork(this.url +
					'/index/user/opendoor.html', {
						dev_id: this.dev_id,
						dev_pwd: this.dev_pwd
					}).then(res => {
					if (res == 'success') {
						uni.showToast({
							title: '已开锁',
							icon: 'none',
							duration: 2000,
							mask: true
						})
						this.clock = 'close'
						this.loading = false
						setTimeout(() => {
							cb&&cb()
						}, 1000)
					} else {
						this.clock = 'close'
						this.loading = false
						uni.showToast({
							title: '开锁失败，请重试（或联系管理员）',
							icon: 'none',
							duration: 3000,
							mask: true
						})
					}
			
				})
			
			}
		}
	}
</script>

<style scoped lang="scss">
	.homePage {
		width: 100vw;
		height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;

		.bgc {
			width: 100%;
			height: 100%;
			position: fixed;
			left: 0;
			top: 0;
		}

		.form {
			width: 730rpx;
			position: fixed;
			left: 50%;
			top: 0;
			transform: translate(-50%, 0);
		}

		.password {
			width: 500rpx;
			height: 80rpx;
			border: 1rpx solid #999;
			border-radius: 20rpx;
			padding-left: 70rpx;
			color: #333;
			box-sizing: border-box;
			line-height: 80rpx;

		}

		.box {
			width: 560rpx;
			position: relative;
			margin-top: 390rpx;
			background-color: #fff;
			padding: 20rpx;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: center;

			text {
				font-size: 44rpx;
				position: absolute;
				left: 50rpx;
				top: 82rpx;
				transform: translateY(-50rpx);
				color: #999;
				font-weight: bold;

			}
		}

		.suo {
			width: 630rpx;
			z-index: 2;
			margin-left: 10rpx;

		}

		.go {
			width: 85vw;
			height: 80rpx;
			margin-top: 60rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background-color: rgba(1, 119, 131, 1);
			color: #fff;
			font-weight: 600;
			letter-spacing: 40rpx;
		}

		.login {
			position: relative;
			text-align: center;

			.iconfont {
				font-size: 200rpx;
				color: #0ab70e;
			}

			button {
				width: 100%;
				height: 100%;
				padding: 0;
				position: absolute;
				left: 0;
				top: 0;
				opacity: 0;
			}

			view {
				color: #999;
				margin-top: 20rpx;
			}
		}
	}
</style>